package com.mycompany.myapp.web.rest.controller;

import com.mycompany.myapp.service.SUserService;
import com.mycompany.myapp.service.dto.SUserDTO;
import com.mycompany.myapp.web.rest.utils.ResultObj;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"后台管理-用户管理"})
@RestController
@RequestMapping("/api")
public class MUserController {
    @Autowired
    private SUserService sUserService;

    @GetMapping("/findByName")
    private ResultObj findByName(@RequestParam(value = "pagenum") int pageNum,
                                 @RequestParam(value = "pagesize") int pageSize,
                                 @RequestParam(value = "query") String username){
        return ResultObj.back(200,sUserService.findByName(pageNum,pageSize,username));
    }

    @PutMapping("update/status")
    private ResultObj updateState(@RequestParam(value = "isActive") boolean isActive,
                                 @RequestParam(value = "userId") long userId){
        return sUserService.updateState(userId,isActive);
    }


    @GetMapping("select/user/{id}")
    private ResultObj findById(@PathVariable Long id){
        return  ResultObj.back(200,sUserService.findById(id));
    }


    @ApiOperation("修改用户信息")
    @PostMapping("/user/update/m")
    public ResultObj updateuserInfo(@RequestBody SUserDTO sUser){
        return sUserService.updateSUserM(sUser);
    }


    @PutMapping("update/role")
    private ResultObj updateRole(@RequestParam(value = "id")  Long id,
                                 @RequestParam(value = "role")  String role){

        return sUserService.updateRole(id,role);
    }



}
